			var current = 0;
			var total = 0;
			var wait = 0;
			var width = 0;
			var margin = 0;
			function next(){
				if(wait || current == total - 1) return;
				wait=1;
				$('#shifting li:eq(' + (current + 2) + ')').show();
				$('#shifting li:eq(' + (current + 0) + ')').animate({
					marginLeft: "-" + (width) + "px"
				  }, 1000, function(){update(+1);});
			}
			function prev(){
				if(wait || current == 0) return;
				wait=1;
				
				$('#shifting li:eq(' + (current - 1) + ')')
					.css('margin-left' , '-' + width + 'px')
					.show()
					.stop()
					.animate({marginLeft: margin}, 1000, function(){
							update(-1);});;
			}
			function update(delta){
				if(delta == 1){
					$('#shifting li:eq(' + (current + 0) + ')').hide().css('margin-left', margin);
				} else if(delta == -1){
					$('#shifting li:eq(' + (current + 1) + ')').hide();
				}
				current+=delta;
				wait=0;
				$('p.log').text('margin: ' + margin + ' , current: ' + current);
				
				updateTopic();
			}
			
			function initShifting(cur){
				current = cur;
				margin = $('#shifting li').css('margin-left');
				width = $('#shifting li').width();
				total = $('#shifting li').size();
				$('ul#shifting').append('<li>End of lecture</li>');
				$('#shifting li').hide();
				$('#shifting li:eq(' + (current + 0) + ')').show();
				$('#shifting li:eq(' + (current + 1) + ')').show();
				bindEvents();
			}
			function bindEvents(){
				leftFunction = function(e){
					prev();
					e.preventDefault();
				};
				$('a.move.left').click(leftFunction);
				
				rightFunction = function(e){
					e.preventDefault();
					next();
				};
				$('a.move.right').click(rightFunction);
				
				$(document.documentElement).keypress(function (event) {
					  // handle cursor keys
					  console.log(event.keyCode);
					if (event.keyCode == 37) {
						leftFunction(event)
					 }
					if(event.keyCode == 39) {
						rightFunction(event)
					}
				});
			}
			
			function recordClassData(topicKey){
				if(!topicKey) {
					topicKey=topics[currentTopic]
				}
				
				$.get('setUpdateTopicStats', 
				{ 
					lectureKey : lectureKey, 
					topicKey : topicKey,
					understand: understand, 
					total: totalStudents 
				});
			}
			function signalTopicChanged(prevTopicKey) {
				recordClassData(prevTopicKey);
				$.get('/setRemoveStudentVotes', {topicKey:prevTopicKey});
			}
			
			function updateTopic()
			{	
				signalTopicChanged(topics[currentTopic])
				
				currentTopic=current;
				$.get('/setCurrentTopic', {
						lectureKey:lectureKey,
						topicKey:topics[currentTopic]},
						function(result) {
							console.log("setCurrentTopic: "+result);
				});
			}
			
			$(function(){
				setInterval(recordClassData, 30 * 1000);
			});
			
